package com.bra.utils;

import java.util.List;

import android.app.Activity;

import com.bra.R;
import com.bra.bean.CityModel;
import com.bra.bean.DistrictModel;
import com.bra.bean.ProvinceModel;
import com.google.gson.Gson;

public class CityDate {
	/**
	 * 所有省
	 */
	public static List<ProvinceModel> mProvinceList;
	/**
	 * 该省列表下所有市
	 */
	public static List<CityModel> mCityList;
	/**
	 * 该市列表下所有区
	 */
	public static List<DistrictModel> mDistricList;

	/**
	 * 解析省市区本地数据
	 */
	public static void initProvinceDatas(Activity activity) {
		Gson gson = new Gson();
		Object obj = gson.fromJson(
				activity.getResources().getString(R.string.city_string),
				ProvinceResult.class);
		if (obj instanceof ProvinceResult) {
			ProvinceResult result = (ProvinceResult) obj;
			mProvinceList = result.city_list;
		}
	}

	/**
	 * 获取所有省名称
	 * */
	public static String[] getProvinceArray() {
		String[] provinceArray;
		if (mProvinceList == null) {
			provinceArray = new String[] { "" };
		} else {
			provinceArray = new String[mProvinceList.size()];
			for (int i = 0; i < mProvinceList.size(); i++) {
				provinceArray[i] = mProvinceList.get(i).area_name;
			}
		}
		return provinceArray;

	}

	/**
	 * 获取当前省列表下的所有市名称
	 * */
	public static String[] getCityArray(int CurrentItem) {
		mCityList = mProvinceList.get(CurrentItem).city;
		String[] cityArray;
		if (mCityList == null) {
			cityArray = new String[] { "" };
		} else {
			cityArray = new String[mCityList.size()];
			for (int i = 0; i < mCityList.size(); i++) {
				cityArray[i] = mCityList.get(i).area_name;
			}
		}
		return cityArray;

	}

	/**
	 * 获取当前市列表下的所有区名称
	 * */
	public static String[] getDistricArray(int CurrentItem) {
		mDistricList = mCityList.get(CurrentItem).town;
		String[] districArray;
		if (mDistricList == null) {
			districArray = new String[] { "" };
		} else {
			districArray = new String[mDistricList.size()];
			for (int i = 0; i < mDistricList.size(); i++) {
				districArray[i] = mDistricList.get(i).area_name;
			}
		}
		return districArray;

	}

	/**
	 * 获取当前选中的区信息
	 * */
	public static DistrictModel getDistric(int CurrentItem) {
		DistrictModel districtModel = mDistricList.get(CurrentItem);
		return districtModel;
	}

	/**
	 * 获取当前选中的市信息
	 * */
	public static CityModel getCity(int CurrentItem) {
		CityModel cityModel = mCityList.get(CurrentItem);
		return cityModel;
	}

	/**
	 * 获取当前选中的省信息
	 * */
	public static ProvinceModel getProvince(int CurrentItem) {
		ProvinceModel provinceModel = mProvinceList.get(CurrentItem);
		return provinceModel;
	}

}
